home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / PopButtonDemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-09  |  8.0 KB  |  298 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/gadgets/PopButton/PopButtonDemo.c,v 41.11 2000/05/09 20:35:15 mlemos Exp $
  3.  *
  4.  * PopButtonDemo.c
  5.  *
  6.  * (C) Copyright 1999 BGUI Developement team.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  *    NMC (12.12.95): Added another menu to demonstrate enabling
  12.  *            and disabling.
  13.  *
  14.  * $Log: PopButtonDemo.c,v $
  15.  * Revision 41.11  2000/05/09 20:35:15  mlemos
  16.  * Bumped to revision 41.11
  17.  *
  18.  * Revision 1.2  2000/05/09 20:00:15  mlemos
  19.  * Merged with the branch Manuel_Lemos_fixes.
  20.  *
  21.  * Revision 1.1.2.1  1999/05/31 01:42:39  mlemos
  22.  * Ian sources.
  23.  *
  24.  *
  25.  *
  26.  */
  27.  
  28. #include <exec/types.h>
  29. #include <libraries/bgui.h>
  30. #include <libraries/bgui_macros.h>
  31.  
  32. #include <clib/alib_protos.h>
  33.  
  34. #include <proto/exec.h>
  35. #include <proto/intuition.h>
  36. #include <proto/bgui.h>
  37. #include <proto/dos.h>
  38. #include <proto/utility.h>
  39.  
  40. /*
  41.  *    Object ID.
  42.  */
  43. #define ID_QUIT                 1
  44. #define ID_POPMENU1        2
  45. #define ID_POPMENU2        3
  46. #define ID_POPMENU3        4
  47. #define ID_POPMENU4        5    /* NMC */
  48.  
  49. /*
  50.  *    Menu entries.
  51.  */
  52. struct PopMenu Project[] = {
  53.     "New",          0, 0,
  54.     "Open...",      0, 0,
  55.     PMB_BARLABEL,    0, 0,
  56.     "Save",         0, 0,
  57.     "Save As...",   0, 0,
  58.     PMB_BARLABEL,    0, 0,
  59.     "Print",        0, 0,
  60.     "Print As...",  0, 0,
  61.     PMB_BARLABEL,    0, 0,
  62.     "About...",     0, 0,
  63.     PMB_BARLABEL,    0, 0,
  64.     "Quit",         0, 0,
  65.     NULL,        0, 0 };
  66.  
  67. struct PopMenu    Edit[] = {
  68.     "Cut",          0, 0,
  69.     "Copy",         0, 0,
  70.     "Paste",        0, 0,
  71.     PMB_BARLABEL,    0, 0,
  72.     "Erase",        0, 0,
  73.     NULL,        0, 0 };
  74.  
  75. /*
  76.  *    This menu has checkable items and mutual exclusion.
  77.  *
  78.  *    The first item will mutually-exclude the last
  79.  *    four items and any of the last four items will
  80.  *    mutually-exclude the first item.
  81.  */
  82. struct PopMenu    Exclude[] = {
  83.     "Uncheck below",        PMF_CHECKIT,                    (1<<2)|(1<<3)|(1<<4)|(1<<5),
  84.     PMB_BARLABEL,        0,                0,
  85.     "Item 1",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  86.     "Item 2",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  87.     "Item 3",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  88.     "Item 4",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  89.     NULL,            0,                0
  90. };
  91.  
  92. /*
  93.  *    This menu has two items that enable the other
  94.  *    when selected. (NMC)
  95.  */
  96. struct PopMenu    Able[] = {
  97.     "Enable below",        0,        0,
  98.     "Enable above",        PMF_DISABLED,    0,
  99.     NULL,            0,        0
  100. };
  101.  
  102. /*
  103.  *    Library base and class base.
  104.  */
  105. struct Library *BGUIBase;
  106.  
  107. /*
  108.  *    Put up a simple requester.
  109.  */
  110. ULONG Req( struct Window *win, UBYTE *gadgets, UBYTE *body, ... )
  111. {
  112.     struct bguiRequest    req = { NULL };
  113.  
  114.     req.br_GadgetFormat    = gadgets;
  115.     req.br_TextFormat    = body;
  116.     req.br_Flags        = BREQF_CENTERWINDOW|BREQF_AUTO_ASPECT|BREQF_LOCKWINDOW|BREQF_FAST_KEYS;
  117.  
  118.     return( BGUI_RequestA( win, &req, ( ULONG * )( &body + 1 )));
  119. }
  120.  
  121. int main( int argc, char **argv )
  122. {
  123.     struct Window        *window;
  124.     Object            *WO_Window, *GO_Quit, *GO_PMB, *GO_PMB1, *GO_PMB2, *GO_PMB3; /* NMC */
  125.     ULONG             signal, rc, tmp = 0;
  126.     UBYTE            *txt;
  127.     BOOL             running = TRUE;
  128.  
  129.     /*
  130.      *    Open BGUI.
  131.      */
  132.     if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  133.             /*
  134.              *    Create the popmenu buttons.
  135.              */
  136.             GO_PMB    = BGUI_NewObject(BGUI_POPBUTTON_GADGET,
  137.                                  PMB_MenuEntries,     Project,
  138.                                  /*
  139.                                   *         Let this one activate
  140.                                   *         the About item.
  141.                                   */
  142.                                  PMB_PopPosition,     9,
  143.                                  LAB_Label,          "_Project",
  144.                                  LAB_Underscore,     '_',
  145.                                  GA_ID,         ID_POPMENU1,
  146.                                  TAG_END );
  147.  
  148.             GO_PMB1 = BGUI_NewObject(BGUI_POPBUTTON_GADGET,
  149.                                  PMB_MenuEntries,     Edit,
  150.                                  LAB_Label,          "_Edit",
  151.                                  LAB_Underscore,     '_',
  152.                                  GA_ID,         ID_POPMENU2,
  153.                                  TAG_END );
  154.  
  155.             GO_PMB2 = BGUI_NewObject(BGUI_POPBUTTON_GADGET,
  156.                                  PMB_MenuEntries,     Exclude,
  157.                                  LAB_Label,          "E_xclude",
  158.                                  LAB_Underscore,     '_',
  159.                                  GA_ID,         ID_POPMENU3,
  160.                                  TAG_END );
  161.  
  162.             GO_PMB3 = BGUI_NewObject(BGUI_POPBUTTON_GADGET,
  163.                                  PMB_MenuEntries,     Able,    /* NMC */
  164.                                  /*
  165.                                   *         Make this menu always
  166.                                   *         appear below the label
  167.                                   */
  168.                                  PMB_PopPosition,     ~0,
  169.                                  LAB_Label,          "E_nable",
  170.                                  LAB_Underscore,     '_',
  171.                                  GA_ID,         ID_POPMENU4,
  172.                                  TAG_END );
  173.             /*
  174.              *    Create the window object.
  175.              */
  176.             WO_Window = WindowObject,
  177.                 WINDOW_Title,        "PopButtonClass Demo",
  178.                 WINDOW_AutoAspect,    TRUE,
  179.                 WINDOW_SmartRefresh,    TRUE,
  180.                 WINDOW_RMBTrap,         TRUE,
  181.                 WINDOW_MasterGroup,
  182.                     VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  183.                         GROUP_BackFill,         SHINE_RASTER,
  184.                         StartMember,
  185.                             HGroupObject, Spacing( 4 ), HOffset( 6 ), VOffset( 4 ),
  186.                                 NeXTFrame,
  187.                                 FRM_BackDriPen,         FILLPEN,
  188.                                 StartMember, GO_PMB, FixMinWidth, EndMember,
  189.                                 StartMember, VertSeparator, EndMember,
  190.                                 StartMember, GO_PMB1, FixMinWidth, EndMember,
  191.                                 StartMember, VertSeparator, EndMember,
  192.                                 StartMember, GO_PMB2, FixMinWidth, EndMember,
  193.                                 StartMember, VertSeparator, EndMember,
  194.                                 StartMember, GO_PMB3, FixMinWidth, EndMember,    /* NMC */
  195.                                 StartMember, VertSeparator, EndMember,        /* NMC */
  196.                             EndObject, FixMinHeight,
  197.                         EndMember,
  198.                         StartMember,
  199.                             InfoFixed( NULL, ISEQ_C
  200.                                      "This demonstrates the usage of the \"PopButtonClass\"\n"
  201.                                      "When you click inside the above popmenu buttons a small\n"
  202.                                      "popup-menu will appear which you can choose from.\n\n"
  203.                                      "You can also key-activate the menus and browse though the\n"
  204.                                      "items using the cursor up and down keys. Return or Enter\n"
  205.                                      "acknowledges the selection and escape cancels it.",
  206.                                      NULL, 7 ),
  207.                         EndMember,
  208.                         StartMember,
  209.                             HGroupObject,
  210.                                 VarSpace( DEFAULT_WEIGHT ),
  211.                                 StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  212.                                 VarSpace( DEFAULT_WEIGHT ),
  213.                             EndObject, FixMinHeight,
  214.                         EndMember,
  215.                     EndObject,
  216.             EndObject;
  217.  
  218.             /*
  219.              *    Object created OK?
  220.              */
  221.             if ( WO_Window ) {
  222.                 /*
  223.                 ** NMC: Amended to not rely on return from
  224.                 ** GadgetKey == 1 exactly. Yes, Jan, I know
  225.                 ** you know it will be 1 - you wrote it! :-)
  226.                 **/
  227.                 if (GadgetKey( WO_Window, GO_Quit,  "q" ) &&
  228.                     GadgetKey( WO_Window, GO_PMB,   "p" ) &&
  229.                     GadgetKey( WO_Window, GO_PMB1,  "e" ) &&
  230.                     GadgetKey( WO_Window, GO_PMB2,  "x" ) &&
  231.                     GadgetKey( WO_Window, GO_PMB3,  "n" )
  232.                     ) {
  233.                     if ( window = WindowOpen( WO_Window )) {
  234.                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  235.                         do {
  236.                             Wait( signal );
  237.                             while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  238.                                 switch ( rc ) {
  239.  
  240.                                     case    WMHI_CLOSEWINDOW:
  241.                                     case    ID_QUIT:
  242.                                         running = FALSE;
  243.                                         break;
  244.  
  245.                                     case    ID_POPMENU4:
  246.                                         GetAttr( PMB_MenuNumber, GO_PMB3, &tmp );
  247.                                         DoMethod( GO_PMB3, PMBM_ENABLE_ITEM, tmp ^ 1 );
  248.                                         DoMethod( GO_PMB3, PMBM_DISABLE_ITEM, tmp );
  249.                                         txt = Able[ tmp ].pm_Label;
  250.                                         goto def;
  251.  
  252.                                     case    ID_POPMENU3:
  253.                                         GetAttr( PMB_MenuNumber, GO_PMB2, &tmp );
  254.                                         txt = Exclude[ tmp ].pm_Label;
  255.                                         goto def;
  256.  
  257.                                     case    ID_POPMENU2:
  258.                                         GetAttr( PMB_MenuNumber, GO_PMB1, &tmp );
  259.                                         txt = Edit[ tmp ].pm_Label;
  260.                                         goto def;
  261.  
  262.                                     case    ID_POPMENU1:
  263.                                         GetAttr( PMB_MenuNumber, GO_PMB, &tmp );
  264.                                         switch ( tmp ) {
  265.                                             case    9:
  266.                                                 Req( window, "*OK", ISEQ_C ISEQ_B "PopButtonClass DEMO\n" ISEQ_N "(C) Copyright 1995 Jaba Development." );
  267.                                                 break;
  268.  
  269.                                             case    11:
  270.                                                 running = FALSE;
  271.                                                 break;
  272.  
  273.                                             default:
  274.                                                 txt = Project[ tmp ].pm_Label;
  275.                                                 def:
  276.                                                 Req( window, "*OK", ISEQ_C "Selected Item %ld <" ISEQ_B "%s" ISEQ_N ">", tmp, txt );
  277.                                                 break;
  278.                                         }
  279.                                         break;
  280.                                 }
  281.                             }
  282.                         } while ( running );
  283.                     }
  284.                 }
  285.                 DisposeObject( WO_Window );
  286.         }
  287.         CloseLibrary( BGUIBase );
  288.     }
  289. }
  290.  
  291. #ifdef _DCC
  292. int wbmain( struct WBStartup *wbs )
  293. {
  294.     return( main( 0, wbs ));
  295. }
  296. #endif
  297.  
  298.